<template lang="jade">
div.return-bar
  i.iconfont(@click="back()") &#xe668;
  提现
div.recharge.detail_top
  header
    div.pic
      img(src="../../assets/images/user/withdraw-cash.png")
  section
    div.box.clearfix
      img.logo(src="../../assets/images/user/huaxingbank-logo.png")
      div.info
        strong 华兴银行账户
        span {{info.bank_acname}}
        span {{info.bank_acno}}
        span {{info.bank_name}}

    div
      div.set-money
        span 提现金额:
        input(placeholder="请输入金额",autofocus,autocomplete="off",type="number",v-model="setMoney",name="money")
      div.money
        span 提现后，账户可用余额 {{initMoney - (parseFloat(setMoney) || 0)}}
      button.btn(type="button", @click="doIt()") 立即提现


    dl.note
      dd
        a.sp(v-link="{ path: '/withdraw-record'}") 查看提现记录
      dt
        b(style="margin-bottom:10px;display:block") 华兴银行提现指引：
        div.ul
          b 1.提现全程免费，请选择合适的提现方式
          p
            实时：10秒内到帐，跨行转账单笔限额5万
          p
            加急：2小时内到账；工作日（除法定节假日）工作时间（8:30-16:59）转账金额≥5万，预计下一个工作日到帐
          p
            普通：24小时内到帐，跨行转账单笔限额5万
          p
            *以上四种提现方式实际到帐时间均取决于收款银行


      dt
        div.ul
          b 2.首次提现需先进行实名认证 查看实名认证
            a.bindingCard( @click="goGet" ) 图文指引>

      dt
        div.ul
          b 3.如提现失败，资金将会被冻结，在30-40分钟之后即可解冻，届时可再次提现

formpage(:url.sync="post_url", :rdata.sync="post_data")
</template>

<script>
import '../../assets/sass/user/recharge.scss'
import {Api_Bind_Card, Api_Bank_Info,Api_Drawing} from '../../config/api'
import FormPage from '../../components/common/form'

export default {

  data () {
    return {
      post_url: '',
      post_data:{},
      busy:false,
      setMoney : '',
      info: {},
      initMoney: 1000,
      subForm:null
    }
  },
  components:{
    formpage:FormPage
  },
  methods: {
    getForm(){
      for(var a in this.$children){
        if(this.$children[a].name == 'form')
          this.subForm = this.$children[a];
      }
    },

    back(){
      //window.history.back();
      this.$route.router.go('/user')
    },

    goGet(){
      this.$router.go('/news/detail/2333')
    },


    bCard(){

      if(this.busy){
        return false;
      }

      this.$store.dispatch('setShowLoading', true);
      this.busy = true;


      this.$http({url:Api_Bind_Card, method:'GET'}).then(function(response){
        var rs = response.data;
        var status = rs.status, msg = rs.msg;
        if(status){
          //window.location.href = Api_Bind_Card+'&r_key='+rkey+'&p_key='+pkey;
          /*this.$children[0].show = true
          this.post_url = rs.action_url
          this.post_data.RequestData = rs.RequestData
          this.post_data.transCode = rs.transCode
          this.$children[0].submit();*/
          this.getForm();
          this.subForm.show = true
          this.post_url = rs.action_url
          this.post_data.RequestData = rs.RequestData
          this.post_data.transCode = rs.transCode
          this.subForm.submit();
        }
        else{
          if(msg == undefined){
            //window.location.href = Api_Bind_Card+'&r_key='+rkey+'&p_key='+pkey;
            /*this.$children[0].show = true
            this.post_url = rs.action_url
            this.post_data.RequestData = rs.RequestData
            this.post_data.transCode = rs.transCode
            this.$children[0].submit();*/
            this.getForm();
            this.subForm.show = true
            this.post_url = rs.action_url
            this.post_data.RequestData = rs.RequestData
            this.post_data.transCode = rs.transCode
            this.subForm.submit();
          }
          else{
            alert(msg);
          }
        }

      });

    },

    fetch: function (next) {
      this.$http({url: Api_Bank_Info, method: 'GET'}).then(function (response) {
        var obj = response.data;
        if(!obj.status){
          alert(obj.msg)
          if(obj.code == '10055'){
            sessionStorage.removeItem("login");
            this.$route.router.go('/login?from=withdraw-cash')
          }
          if(obj.code == '10057'){
            this.$router.go('/openAccount')
          }
        }else{
          this.info = obj.data
          this.initMoney = parseFloat(obj.data.balance)
        }

        next()
      }, function (response) {
          console.log(response)
      });
    },



    doIt: function () {

      if(this.initMoney - Math.abs(parseInt(this.setMoney)) < 0){
        alert('您的帐号余额不足，提现失败！')
        return false;
      }

      if(this.busy){
        return false;
      }
      this.$store.dispatch('setShowLoading', true);
      this.busy = true;
      var data = {'money':this.setMoney}

      this.$http.post(Api_Drawing, data,'').then(function (response) {
          var rs = response.data;
          this.$store.dispatch('setShowLoading', false);

          if(!rs.status){
            alert(rs.msg)
            this.busy = false;
          }else {

/*            this.$children[0].show = true
            this.post_url = rs.action_url
            this.post_data.RequestData = rs.RequestData
            this.post_data.transCode = rs.transCode
            this.$children[0].submit();*/
            this.getForm();
            this.subForm.show = true
            this.post_url = rs.action_url
            this.post_data.RequestData = rs.RequestData
            this.post_data.transCode = rs.transCode
            this.subForm.submit();


          }
      }, function (response) {

      });


    }
  },
  route: {
    activate ( transition ) {

      this.fetch( function() {
        transition.next();
      })
    }
  }
}
</script>


<style lang="scss" scoped>
.ul{
  margin-bottom:15px;
  b{
    margin-bottom:10px;
    display:block;
  }
  p{
    margin-bottom:5px;
    font-size:13px
  }
}
</style>
